package triggerhelper.dataHolders;

import java.io.Serializable;
import javax.swing.DefaultListModel;
import javax.swing.event.ListDataEvent;

public class Variable implements Serializable {

    private static final long serialVersionUID = 1L;
    private String name;
    private int iterate, minValue, maxValue;
    private DefaultListModel instances;
    private boolean isVarNumber;
    private boolean hasSaved = false;
    private Trigger t;

    public Variable(Trigger t_, String name_){
        t = t_;
        name = name_;
        instances = new DefaultListModel();
    }

    @Override
    public String toString(){
        String result = "";
        if(!hasSaved){
            result += "**";
        }else if(isVarNumber){
            result += "(#) - ";
        }else{
            result += "(w) - ";
        }
        result += name;

        return result;
    }
    public String getInstance(int index){
        return (String)instances.getElementAt(index);
    }
    public void setSaved(boolean b){
        hasSaved = b;
    }

    // <editor-fold defaultstate="collapsed" desc="Getters/Setters">
    //getters/setters
    public boolean getHasSaved() {
        return hasSaved;
    }

    public void setIsNumber(boolean a) {
        if (isVarNumber != a) {
            isVarNumber = a;
            t.setSaved(false);
        }
    }

    public boolean isNumber() {
        return isVarNumber;
    }

    public void setMinValue(int aValue) {
        if (minValue != aValue) {
            minValue = aValue;
            t.setSaved(false);
        }
    }

    public int getMinValue() {
        return minValue;
    }

    public void setMaxValue(int aValue) {
        if (maxValue != aValue) {
            maxValue = aValue;
            t.setSaved(false);
        }
    }

    public int getMaxValue() {
        return maxValue;
    }

    public DefaultListModel getInstances() {
        return instances;
    }

    public int getIterate() {
        return iterate;
    }

    public void setIterate(int i) {
        if (iterate != i) {
            iterate = i;
            t.setSaved(false);
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String s) {
        if (!name.equals(s)) {
            name = s;
            t.setSaved(false);
        }
    }// </editor-fold>
}
